package com.fql.research.common.jms;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

/**
 * 发布订阅发布者
 * @author fanql 2017年7月12日
 *
 */
@Resource
@Component("topicSender")
public class TopicSender {
	@Resource(name = "jmsTopicTemplate")
    private JmsTemplate jmsTopicTemplate;// 通过@Qualifier修饰符来注入对应的bean
	
	public void send(String destination,final Object message) {
		jmsTopicTemplate.send(destination, new MessageCreator() {
			
			@Override
			public Message createMessage(Session session) throws JMSException {
				return jmsTopicTemplate.getMessageConverter().toMessage(message, session);
			}
		});
	}
}
